package org.zdc.pivot.wtk;
import nme.text.Font;
import org.zdc.core.IllegalArgumentException;
import org.zdc.pivot.wtk.skin.ButtonSkin;
import org.zdc.pivot.wtk.skin.BoxPaneSkin;
import org.zdc.pivot.wtk.skin.CardPaneSkin;
import org.zdc.pivot.wtk.skin.ColorChooserButtonSkin;
import org.zdc.pivot.wtk.skin.FillPaneSkin;
import org.zdc.pivot.wtk.skin.FlowPaneSkin;
import org.zdc.pivot.wtk.skin.GridPaneSkin;
import org.zdc.pivot.wtk.skin.GridPaneFillerSkin;
import org.zdc.pivot.wtk.skin.ImageViewSkin;
import org.zdc.pivot.wtk.skin.ISkin;
import org.zdc.pivot.wtk.skin.LabelSkin;
import org.zdc.pivot.wtk.skin.MovieViewSkin;
import org.zdc.pivot.wtk.skin.PanelSkin;
import org.zdc.pivot.wtk.skin.ScrollPaneSkin;
import org.zdc.pivot.wtk.skin.SeparatorSkin;
import org.zdc.pivot.wtk.skin.StackPaneSkin;
import org.zdc.pivot.wtk.skin.TablePaneSkin;
import org.zdc.pivot.wtk.skin.TablePaneFillerSkin;
import org.zdc.pivot.wtk.skin.TextAreaSkin;
import org.zdc.pivot.wtk.skin.TextPaneSkin;
import org.zdc.pivot.wtk.skin.WindowSkin;

class Theme 
{
	private var componentSkinMap:nme.ObjectHash < Class<Component>, Class<ISkin> >;
	private static var theme:Theme;
	
	public static inline var NAME_KEY = "name";
    public static inline var SIZE_KEY = "size";
    public static inline var BOLD_KEY = "bold";
    public static inline var ITALIC_KEY = "italic";
	
	/**
	 * 服务提供器的名字(查看 Service#getProvider(String))
	 */
	public static inline var PROVIDER_NAME = "org.apache.pivot.wtk.Theme";
	
	public function new() 
	{
		componentSkinMap = new nme.ObjectHash < Class<Component>, Class<ISkin> > ();
		
		componentSkinMap.set(Border, ButtonSkin);
		componentSkinMap.set(BoxPane, BoxPaneSkin);
		componentSkinMap.set(CardPane, CardPaneSkin);
		componentSkinMap.set(ColorChooserPopup, ColorChooserButtonSkin);
		componentSkinMap.set(FillPane, FillPaneSkin);
		componentSkinMap.set(FlowPane, FlowPaneSkin);
		componentSkinMap.set(GridPane, GridPaneSkin);
		componentSkinMap.set(GridPaneFiller, GridPaneFillerSkin);
		componentSkinMap.set(ImageView, ImageViewSkin);
		componentSkinMap.set(Label, LabelSkin);
		componentSkinMap.set(MovieView, MovieViewSkin);
		componentSkinMap.set(Panel, PanelSkin);
		componentSkinMap.set(ScrollPane, ScrollPaneSkin);
		componentSkinMap.set(Separator, SeparatorSkin);
		componentSkinMap.set(StackPane, StackPaneSkin);
		componentSkinMap.set(TablePane, TablePaneSkin);
		componentSkinMap.set(TablePaneFiller, TablePaneFillerSkin);
		componentSkinMap.set(TextArea, TextAreaSkin);
		componentSkinMap.set(TextPane, TextPaneSkin);
		componentSkinMap.set(Window, WindowSkin);
	}
	
	public function getSkinClass(compClass:Class<Component>):Class<ISkin> {
		return componentSkinMap.get(compClass);
	}
	
	public function getFont():Font {
		return null;
	}
	
	public function setFont(font:Font):Void {
		
	}
	
	/**
	 * 获取皮肤类
	 * @param	compClass
	 * @return
	 */
	public function get(compClass:Class<Component>):Class<ISkin> {
		if (compClass == null) {
			throw new IllegalArgumentException("Component class is null.");
		}
		
		return componentSkinMap.get(compClass);
	}
	
	/**
	 * 设置组件类对应的皮肤类
	 * @param	compClass
	 * @param	skinClass
	 */
	public function set(compClass:Class<Component>, skinClass:Class<ISkin>):Void {
		if (compClass == null) {
			throw new IllegalArgumentException("Component class is null.");
		}
		if (skinClass == null) {
			throw new IllegalArgumentException("Skin class is null");
		}
		
		componentSkinMap.set(compClass, skinClass);
	}
	
	public static function getTheme():Theme {
		if (theme == null) {
			throw new IllegalArgumentException("No installed theme");
		}
		return theme;
	}
	
	public static function deriveFont(dictionary:Hash<Dynamic>):Font {
		return null; 
	}
}